<template>
  <!-- 文章列表卡片 -->
  <div class="card">
    <div class="view">
      <!-- 头部 -->
      <div class="head">
        <div class="title">{{ articleInfo.title.slice(0, 17) }}...</div>
        <div class="time">
          <img
            src="https://vue-wj.oss-cn-beijing.aliyuncs.com/icon/%E6%97%A5%E5%8E%86.png"
          />
          <p>{{ articleInfo.createTime }}</p>
        </div>
      </div>
      <!-- 主体 -->
      <div class="body">
        <span>{{ previewText }}</span>
      </div>
      <!-- 底部 -->
      <div class="footer">
        <!-- 标签 -->
        <div class="left">
          <div class="label" v-for="item in articleInfo.tags" :key="item.id">
            <img
              src="https://vue-wj.oss-cn-beijing.aliyuncs.com/icon/%E6%A0%87%E7%AD%BE_1.png"
            />
            <p>{{ item.name }}</p>
          </div>
        </div>
        <!-- 图标 -->
        <div class="right">
          <div class="icon">
            <img
              src="https://vue-wj.oss-cn-beijing.aliyuncs.com/icon/%E5%96%9C%E6%AC%A2.png"
            />
            <p>{{ articleInfo.likeCount }}</p>
          </div>
          <div class="icon">
            <img
              src="https://vue-wj.oss-cn-beijing.aliyuncs.com/icon/%E7%95%99%E8%A8%80.png"
            />
            <p>{{ articleInfo.commentCount }}</p>
          </div>
          <div class="icon">
            <img
              src="https://vue-wj.oss-cn-beijing.aliyuncs.com/icon/%E8%89%B2%E5%9D%97%EF%BC%8D%E6%96%87%E6%9C%AC%E6%9F%A5%E7%9C%8B.png"
            />
            <p>{{ articleInfo.viewCount }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from "vue";

const props = defineProps({
  articleInfo: {
    type: Object,
    required: true,
  },
});

// 计算预览文本
const previewText = computed(() => {
  // 移除 Markdown 语法标记
  const plainText = props.articleInfo.content
    .replace(/<pre><code.*?>(.*?)<\/code><\/pre>/gs, "")
    .replace(/<[^>]*>/g, "")
    .replace(/&nbsp;/g, "")
    .trim();

  // 截取前200个字符
  return plainText.slice(0, 200) + "...";
});
</script>

<style lang="scss" scoped>
.card {
  margin: 0 auto;
  margin-bottom: 24px;
  width: 100%;
  padding: 10px 20px;
  min-height: 120px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.03);
  cursor: pointer;
  transition: all 0.3s;

  &:hover {
    transform: scale(1.05);
    border: 0.5px solid #91e2f3c0;
    box-shadow: 2px 2px 10px rgba(193, 226, 243, 0.7);
  }

  // 头部
  .head {
    min-height: 36px;
    line-height: 36px;
    padding: 0px 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    // 标题
    .title {
      flex-basis: auto;
      color: rgb(60, 63, 67);
      font-size: 18px;
      font-weight: 600;
    }

    // 时间
    .time {
      flex-basis: auto;
      font-size: 13px;
      display: flex;
      align-items: center;
      gap: 10px;
      color: rgba(90, 89, 89, 0.7);

      img {
        width: 24px;
        height: 24px;
      }
    }
  }

  // 主体
  .body {
    min-height: 70px;
    text-indent: 2em;
    line-height: 1.6;
    color: rgba(51, 50, 50, 0.7);

    // 内容
    span {
      background: linear-gradient(to right, #e0e32f, #9ee32f) no-repeat;
      background-size: 0 2px;
      background-position: right bottom;
      transition: background-size 1s;

      &:hover {
        background-size: 100% 1px;
        background-position: left bottom;
      }
    }
  }

  .footer {
    height: 45px;
    line-height: 45px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;

    @media (max-width: 768px) {
      height: auto;

      .left {
        justify-content: end;
        height: 30px;
        width: 100%;
        gap: 8px;

        .label {
          gap: 4px;

          img {
            width: 20px;
            height: 20px;
          }

          p {
            font-size: 14px;
          }
        }
      }

      .right {
        justify-content: end;
        height: 30px;
        width: 100%;
        gap: 16px;

        .icon {
          gap: 4px;

          img {
            width: 20px;
            height: 20px;
          }

          p {
            font-size: 14px;
          }
        }
      }
    }

    // 标签
    .left {
      flex: 1;
      display: flex;
      gap: 10px;

      .label {
        display: flex;
        align-items: center;
        gap: 5px;

        img {
          width: 24px;
          height: 24px;
        }
      }
    }

    // 图标
    .right {
      display: flex;
      gap: 20px;

      .icon {
        display: flex;
        align-items: center;
        gap: 5px;

        img {
          width: 24px;
          height: 24px;
        }
      }
    }
  }
}

// ✅ 统一的 @media 规则
@media (max-width: 768px) {
  .card {
    width: 100%;
    margin-bottom: 16px;
    padding: 8px 16px;
  }

  .head {
    height: auto;
    flex-direction: column;
    gap: 8px;

    .title {
      font-size: 16px;
      line-height: 1.4;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .time {
      font-size: 12px;

      img {
        width: 18px;
        height: 18px;
      }
    }
  }

  .body {
    min-height: 50px;
    padding: 0 12px;
    font-size: 14px;
  }
}
</style>